﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace Treasland.MassiveGridMap.Editor {
    public class Connection : Node {
        public ConnectionPoint startPoint;
        public ConnectionPoint targetPoint;
        private Vector2 startPos;
        private Vector2 endPos;

        private Action<Connection> onDeletedCallback;

        public Connection(Action<Connection> _onDeletedCallback, enNodeType _type = enNodeType.Connection) : base(_type) {
            onDeletedCallback = _onDeletedCallback;

        }

        public override bool ProcessEvent(Event e) {
            return base.ProcessEvent(e);
        }

        public override void Draw() {
            base.Draw();
            if(startPoint == null) {
                return;
            }

            Event e = Event.current;

            startPos = startPoint.rect.center;

            if(targetPoint != null) {
                endPos = targetPoint.rect.center;
            } else {
                endPos = Event.current.mousePosition;
            }

            Handles.DrawBezier(startPos,
                               endPos,
                               startPos - Vector2.left * 50,
                               endPos + Vector2.left * 50,
                               Color.red,
                               null,
                               3.0f);
            
        }

        public void AddStartPoint(ConnectionPoint _point) {
            startPoint = _point;
        }

        public void AddTargetPoint(ConnectionPoint _point) {
            targetPoint = _point;
        }
    }
}
